package org.domain.sigepac.Entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.validator.NotNull;

@Entity
@Table(name = "tb_frequencia_voluntario")
public class FrequenciaVoluntario extends EntidadeAbstrata implements Comparable<FrequenciaVoluntario> {

	private static final long serialVersionUID = 2624449853716240343L;


	public FrequenciaVoluntario() {
		this.id.setData(new Date());
	}

	@EmbeddedId
	private FrequenciaVoluntarioId id=new FrequenciaVoluntarioId();

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_voluntario", insertable = false, updatable = false)
	private Voluntario voluntario;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_turma", insertable = false, updatable = false)
	private Turma turma;


	@Column(name="presente",nullable=false)
	@NotNull
	private boolean presente;

	public void setData(Date data){
		this.id.setData(data);
	}

	public Date getData(){
		return this.id.getData();
	}

	public boolean isPresente() {
		return presente;
	}

	public void setPresente(boolean presente) {
		this.presente = presente;
	}

	public Serializable getId() {
		// TODO Auto-generated method stub
		return id;
	}

	public Voluntario getVoluntario() {
		return voluntario;
	}

	public void setVoluntario(Voluntario voluntario) {
		this.voluntario = voluntario;
		((FrequenciaVoluntarioId) getId()).setIdVoluntario((Integer)voluntario.getId());
	}

	public Turma getTurma() {
		return turma;
	}

	public void setTurma(Turma turma) {
		this.turma = turma;
		((FrequenciaVoluntarioId) getId()).setIdTurma((Integer)turma.getId());

	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((voluntario == null) ? 0 : voluntario.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + (presente ? 1231 : 1237);
		result = prime * result + ((turma == null) ? 0 : turma.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		FrequenciaVoluntario other = (FrequenciaVoluntario) obj;
		if (voluntario == null) {
			if (other.voluntario != null)
				return false;
		} else if (!voluntario.equals(other.voluntario))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (presente != other.presente)
			return false;
		if (turma == null) {
			if (other.turma != null)
				return false;
		} else if (!turma.equals(other.turma))
			return false;
		return true;
	}

	public int compareTo(FrequenciaVoluntario o) {
		// TODO Auto-generated method stub
		return this.getVoluntario().getNome().compareTo(o.getVoluntario().getNome());
	}


}
